<?php

/**
 *TrainerCity 商品类型管理程序 *
 
 * $Id: goods_type.php 17063 2010-03-25 06:35:46Z  $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

$exc = new exchange($ecs->table("goods_type"), $db, 'cat_id', 'cat_name');

/*------------------------------------------------------ */
//-- Manage UI
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'manage')
{
    #assign_query_info();

    $smarty->assign('ur_here',          $_LANG['08_goods_type']);
    $smarty->assign('full_page',        1);

	#add by wanglei
	$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('credentials');
	$credentialstype=$db->getAll($sql);
	$smarty->assign('credentials_type_arr',   $credentialstype);
	#end by wanglei
	$smarty->assign('action_link',      array('text' => 'Add New Type', 'href' => 'credentials.php?act=add'));

    $smarty->display('credentials_type.htm');
}

/*------------------------------------------------------ */
//-- Add New Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'add_newtype')
{
	$new_type = !empty($_POST['new_type']) ? trim($_POST['new_type']) : '';
	 
	if($new_type)
	{
		/*Insert*/	
		$sql = "INSERT INTO " . $ecs->table('credentials') . "(credentialsType) VALUES ('" . $new_type . "')";
    	if($db->query($sql) != false)
		{
			/*Add Successfully*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("New Type Add Successfully!", 0, $links);
		}
		else
		{
			/*Add Failed*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("Failed, please try again!", 0, $links);
		}
	}
	else
	{
		/*No new type*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("Please input new type!", 0, $links);
	}
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'modify')
{
	$cat_id = !empty($_GET['cat_id']) ? intval($_GET['cat_id']) : '';
	
	#add by wanglei
	$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('credentials')." WHERE xid='$cat_id' ";
	$credentialstype=$db->getRow($sql);
		
	$smarty->assign('credentials_type',   $credentialstype);
	#end by wanglei
	$smarty->assign('action_link',      array('text' => 'Add New Type', 'href' => 'credentials.php?act=add'));

    $smarty->display('credentials_type_add.htm');
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'act_modify')
{
	$old_cat_id = $_REQUEST['cat_id'];
	$new_cat_id = $_POST['type_num'];
	$credentials_type = !empty($_POST['credentials_type']) ? trim($_POST['credentials_type']) : '';
	
	if($new_cat_id!="" && $credentials_type)
	{
		#add by wanglei
		$sql = "UPDATE " . $GLOBALS['ecs']->table('credentials') .
            " SET xid='$new_cat_id', credentialsType='$credentials_type' WHERE xid='$old_cat_id' ";
		if($db->query($sql) != false)
		{
			/*Modify Successfully*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("Modify Type Successfully!", 0, $links);
			
		}
		else
		{
			/*Modify Failed*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("Failed, please try again!", 0, $links);
		}
	}
	else
	{
			/*Modify Failed*/	
			$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        	sys_msg("Please input the num and tyep!", 0, $links);
	}
	
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'delete')
{
	$cat_id = !empty($_GET['cat_id']) ? intval($_GET['cat_id']) : '';
		
	#add by wanglei
	$sql = "DELETE FROM " . $GLOBALS['ecs']->table('credentials') .
            " WHERE xid='$cat_id' ";
	if($db->query($sql) != false)
	{
		/*Modify Successfully*/	
		$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        sys_msg("Delete Type Successfully!", 0, $links);
			
	}
	else
	{
		/*Modify Failed*/	
		$links = array(array('href' => 'credentials.php?act=manage', 'text' => "credentials Type List"));
        sys_msg("Failed, please try again!", 0, $links);
	}	
}

?>
